﻿#region License
/* Copyright (C) 2009 Tim Coulter
 * 
 * This file is part of ExtremeML.
 * 
 * ExtremeML is free software: you can redistribute
 * it and/or modify it under the terms of the GNU General Public
 * License, as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
 * the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
*/
#endregion

using ExtremeML.Spreadsheet.Address;

namespace ExtremeML.Spreadsheet
{
	// This is a partial class that adds custom functionality to its auto-generated partner.
	public sealed partial class TableColumnWrapper
	{
		#region Custom Properties

		/// <summary>
		/// Gets the containing <see cref="TableWrapper"/>.
		/// </summary>
		public TableWrapper Table
		{
			get { return (TableWrapper)Parent.Parent.Parent; }
		}

		/// <summary>
		/// Gets the zero-based index of this item in its parent collection.
		/// </summary>
		public int Index
		{
			get { return ((TableColumnWrapperCollection)Parent).IndexOf(this); }
		}

		/// <summary>
		/// Gets the zero-based index of the worksheet column associated with this table column.
		/// </summary>
		public int WorksheetColumnIndex
		{
			get { return Table.FirstColumnIndex.Value + Index; }
		}

		#endregion
		#region Custom Methods


		#endregion
		#region Overrides

		/// <summary>
		/// Intercepts setting of the <see cref="Name"/> property and updates underlying cell value to match.
		/// </summary>
		partial void OnNamePropertyChanging(
			ref string value,
			string _name)
		{
			Table.Worksheet.SetCellValue(
				new GridReference(Table.FirstRowIndex.Value, Table.FirstColumnIndex.Value + Index),
				value);			
		}

		#endregion
		#region Implementation Methods


		#endregion
		#region Static Methods


		#endregion
	}
}
